﻿@{
    ViewBag.Title = "ResourceList";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}
<script type="text/javascript">
    $(function () {
        var height = $("#divTotal").height();
        var master = $("#master").height();
        var content = parseFloat(height) - parseFloat(master) - 30;
        $("#tbList").css("height", content);
    });
</script>
<script type="text/javascript">
    $(function () {
        $("#tbList").datagrid({
            url: '/Train/getResourceList',
            loadMsg: '数据加载中请稍后……',
            pagination: true,
            rownumbers: true,
            idField: "Id",
            queryParams: com.serializeSearchArray("form1"),
            singleSelect: true,
            pageSize: 20,
            pageList: [20, 50, 100],
            striped: true,
            columns: [[
               {
                   field: 'ck', checkbox: true, width: 30
               },
               {
                   field: 'FIleAllName', title: '文档名称', width: 580, align: "center"
               },
               //{
               //    field: 'FileType', title: '文档类型', width: 110, align: "center",
               //    formatter: function (value, row, index) {
               //        return com.getArrayText(StaticCombo.FileType, value);
               //    }
               //},
               {
                   field: 'Category', title: '文档类别', width: 110, align: "center",
                   formatter: function (value, row, index) {
                       return com.getArrayText(StaticCombo.Category, value);
                   }
               },
               {
                   field: 'FileSize', title: '文档大小', width: 100, align: "center",
                   formatter: function (value, row, index) {
                       return (value / (1024 * 1024)).toFixed(1) + "MB";
                   }
               },
                {
                    field: 'AddName', title: '上传用户', width: 100, align: "center"
                },
                {
                    field: 'AddTime', title: '上传时间', width: 150, align: "center"
                },
                {
                    field: 'view', title: '浏览', align: 'center', width: 80, align: "center",
                    formatter: function (value, row, index) {
                        return "<i name='view' class='fa fa-eye' aria-hidden='true' onclick='view(" + JSON.stringify(row) + ")'></i>";
                    }
                },
                {
                    field: 'Download', title: '下载', align: 'center', width: 80, align: "center",
                    formatter: function (value, row, index) {
                        if (value == "0") {
                            return "<i name='download' class='fa fa-download' aria-hidden='true' onclick='download(" + row.FileID + ")'></i>";
                        }
                        else {
                            return "";
                        }
                    }
                },
            ]],
        });
    });
</script>
<script>
    function view(row)//按文件类别寻找不同的在线浏览方法
    {
        //console.log(row);
        if (row.FileType == ".pdf") {
            $.showLoading();
            com.ajax({
                url: "/BD/File/ViewPDF",
                data: { ID: row.FileID },
                success: function (data) {
                    $.hideLoading();
                    window.open('../../ViewFiles/' + data.msg);
                }
            })
        }
        else if (row.FileType == ".doc" || row.FileType == ".docx")
        {
            $.showLoading();
            com.ajax({
                url: "/BD/File/ViewWord",
                data: { ID: row.FileID },
                success: function (data) {
                    $.hideLoading();
                    window.open('../../ViewFiles/' + data.msg);
                }
            })
        }
        else if (row.FileType == ".mp4" || row.FileType == ".mkv") {
            $.showLoading();
            com.ajax({
                url: "/BD/File/ViewMP4",
                data: { ID: row.FileID },
                success: function (data) {
                    $.hideLoading();
                    //window.open('../../ViewFiles/' + data.msg);\
                    top.wrapper.addTab("视频播放", "/ZY/Train/VideoPlayer?url="+data.msg);
                }
            })
        }
    }
    function download(id) {
        var url = "/BD/File/Download";
        var form = $("<form></form>").attr("action", url).attr("method", "post");
        form.append($("<input></input>").attr("type", "hidden").attr("name", "id").attr("value", id));
        form.appendTo('body').submit().remove();
    }
    function funcSearch() {
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);
    }
    function funcAdd() {
        layer.open({
            type: 2, //Page层类型
            area: ['600px', '500px'],
            title: '文件上传',
            shade: 0.6, //遮罩透明度
            maxmin: true,  //允许全屏最小化
            anim: 1, //0-6的动画形式，-1不开启
            content: '/ZY/Train/AddFile',
            cancel: function (index, layero) {
                layer.close(index);
                location.reload();
            }
        });
    }
    function funcEdit() {

    }
    function funcRemove() {
        $.messager.confirm('确认对话框', '您确定删除该文件吗？', function (r) {
            if (r) {
                var rowData = $("#tbList").datagrid("getSelected");
                if (rowData) {
                    com.ajax({
                        url: '/Train/DeleteFile',
                        data: { ID: rowData.ID },
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); $("#tbList").datagrid("clearSelections"); });
                        }
                    });
                }
            }
        });
    }
    function funcSave() {

    }
    function funcCancel() {

    }
    function funcReload() {
        $("#form1").form("reset");
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);
    }
</script>
<div id="divTotal" style="height: 100%; width: 100%">
    <div style="margin:5px" id="master">
        <form id="form1">
            <input id="FIleAllName" name="FIleAllName" class="easyui-textbox" data-options="prompt:'文档名称'" data-cp="co">
        </form>
    </div>
    <table id="tbList" title="资源信息表 " style="width: 100%"></table>
</div>
